import UIKit

class TimeTemperatureCell: UITableViewCell {

    var timeLabel: UILabel!
    var temperatureLabel: UILabel!

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        // 初始化标签
        timeLabel = UILabel()
        temperatureLabel = UILabel()

        // 设置标签样式
        timeLabel.font = UIFont.systemFont(ofSize: 16)
        timeLabel.textColor = .black

        temperatureLabel.font = UIFont.systemFont(ofSize: 16)
        temperatureLabel.textColor = .blue
        temperatureLabel.textAlignment = .right

        // 将标签添加到内容视图
        contentView.addSubview(timeLabel)
        contentView.addSubview(temperatureLabel)

        // 禁用自动调整尺寸
        timeLabel.translatesAutoresizingMaskIntoConstraints = false
        temperatureLabel.translatesAutoresizingMaskIntoConstraints = false

        // 设置 Auto Layout 约束
        NSLayoutConstraint.activate([
            // timeLabel 约束
            timeLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16),
            timeLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),

            // temperatureLabel 约束
            temperatureLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16),
            temperatureLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
            
            // 设置宽度比例，可以根据需求调整
            timeLabel.trailingAnchor.constraint(equalTo: temperatureLabel.leadingAnchor, constant: -8),
            temperatureLabel.widthAnchor.constraint(equalTo: timeLabel.widthAnchor)
        ])
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // 配置单元格数据
    func configure(time: String, temperature: String) {
        timeLabel.text = time
        temperatureLabel.text = temperature
    }
}

